home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
os2
/
e33el2.zip
/
emacs
/
19.33
/
lisp
/
perl-mode.el
< prev
next >
Wrap
Lisp/Scheme
|
1996-02-27
|
30KB
|
727 lines
;;; perl-mode.el --- Perl code editing commands for GNU Emacs
;; Copyright (C) 1990, 1994 Free Software Foundation, Inc.
;; Author: William F. Mann
;; Maintainer: FSF
;; Adapted-By: ESR
;; Keywords: languages
;; Adapted from C code editing commands 'c-mode.el', Copyright 1987 by the
;; Free Software Foundation, under terms of its General Public License.
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; To enter perl-mode automatically, add (autoload 'perl-mode "perl-mode")
;; to your .emacs file and change the first line of your perl script to:
;; #!/usr/bin/perl -- # -*-Perl-*-
;; With arguments to perl:
;; #!/usr/bin/perl -P- # -*-Perl-*-
;; To handle files included with do 'filename.pl';, add something like
;; (setq auto-mode-alist (append (list (cons "\\.pl\\'" 'perl-mode))
;; auto-mode-alist))
;; to your .emacs file; otherwise the .pl suffix defaults to prolog-mode.
;; This code is based on the 18.53 version c-mode.el, with extensive
;; rewriting. Most of the features of c-mode survived intact.
;; I added a new feature which adds functionality to TAB; it is controlled
;; by the variable perl-tab-to-comment. With it enabled, TAB does the
;; first thing it can from the following list: change the indentation;
;; move past leading white space; delete an empty comment; reindent a
;; comment; move to end of line; create an empty comment; tell you that
;; the line ends in a quoted string, or has a # which should be a \#.
;; If your machine is slow, you may want to remove some of the bindings
;; to electric-perl-terminator. I changed the indenting defaults to be
;; what Larry Wall uses in perl/lib, but left in all the options.
;; I also tuned a few things: comments and labels starting in column
;; zero are left there by indent-perl-exp; perl-beginning-of-function
;; goes back to the first open brace/paren in column zero, the open brace
;; in 'sub ... {', or the equal sign in 'format ... ='; indent-perl-exp
;; (meta-^q) indents from the current line through the close of the next
;; brace/paren, so you don't need to start exactly at a brace or paren.
;; It may be good style to put a set of redundant braces around your
;; main program. This will let you reindent it with meta-^q.
;; Known problems (these are all caused by limitations in the Emacs Lisp
;; parsing routine (parse-partial-sexp), which was not designed for such
;; a rich language; writing a more suitable parser would be a big job):
;; 1) Regular expression delimiters do not act as quotes, so special
;; characters such as `'"#:;[](){} may need to be backslashed
;; in regular expressions and in both parts of s/// and tr///.
;; 2) The globbing syntax <pattern> is not recognized, so special
;; characters in the pattern string must be backslashed.
;; 3) The q, qq, and << quoting operators are not recognized; see below.
;; 4) \ (backslash) always quotes the next character, so '\' is
;; treated as the start of a string. Use "\\" as a work-around.
;; 5) To make variables such a $' and $#array work, perl-mode treats
;; $ just like backslash, so '$' is the same as problem 5.
;; 6) Unfortunately, treating $ like \ makes ${var} be treated as an
;; unmatched }. See below.
;; 7) When ' (quote) is used as a package name separator, perl-mode
;; doesn't understand, and thinks it is seeing a quoted string.
;; Here are some ugly tricks to bypass some of these problems: the perl
;; expression /`/ (that's a back-tick) usually evaluates harmlessly,
;; but will trick perl-mode into starting a quoted string, which
;; can be ended with another /`/. Assuming you have no embedded
;; back-ticks, this can used to help solve problem 3:
;;
;; /`/; $ugly = q?"'$?; /`/;
;;
;; To solve problem 6, add a /{/; before each use of ${var}:
;; /{/; while (<${glob_me}>) ...
;;
;; Problem 7 is even worse, but this 'fix' does work :-(
;; $DB'stop#'
;; [$DB'line#'
;; ] =~ s/;9$//;
;;; Code:
(defvar perl-mode-abbrev-table nil
"Abbrev table in use in perl-mode buffers.")
(define-abbrev-table 'perl-mode-abbrev-table ())
(defvar perl-mode-map ()
"Keymap used in Perl mode.")
(if perl-mode-map
()
(setq perl-mode-map (make-sparse-keymap))
(define-key perl-mode-map "{" 'electric-perl-terminator)
(define-key perl-mode-map "}" 'electric-perl-terminator)
(define-key perl-mode-map ";" 'electric-perl-terminator)
(define-key perl-mode-map ":" 'electric-perl-terminator)
(define-key perl-mode-map "\e\C-a" 'perl-beginning-of-function)
(define-key perl-mode-map "\e\C-e" 'perl-end-of-function)
(define-key perl-mode-map "\e\C-h" 'mark-perl-function)
(define-key perl-mode-map "\e\C-q" 'indent-perl-exp)
(define-key perl-mode-map "\177" 'backward-delete-char-untabify)
(define-key perl-mode-map "\t" 'perl-indent-command))
(autoload 'c-macro-expand "cmacexp"
"Display the result of expanding all C macros occurring in the region.
The expansion is entirely correct because it uses the C preprocessor."
t)
(defvar perl-mode-syntax-table nil
"Syntax table in use in perl-mode buffers.")
(if perl-mode-syntax-table
()
(setq perl-mode-syntax-table (make-syntax-table (standard-syntax-table)))
(modify-syntax-entry ?\n ">" perl-mode-syntax-table)
(modify-syntax-entry ?# "<" perl-mode-syntax-table)
(modify-syntax-entry ?$ "/" perl-mode-syntax-table)
(modify-syntax-entry ?% "." perl-mode-syntax-table)
(modify-syntax-entry ?& "." perl-mode-syntax-table)
(modify-syntax-entry ?\' "\"" perl-mode-syntax-table)
(modify-syntax-entry ?* "." perl-mode-syntax-table)
(modify-syntax-entry ?+ "." perl-mode-syntax-table)
(modify-syntax-entry ?- "." perl-mode-syntax-table)
(modify-syntax-entry ?/ "." perl-mode-syntax-table)
(modify-syntax-entry ?< "." perl-mode-syntax-table)
(modify-syntax-entry ?= "." perl-mode-syntax-table)
(modify-syntax-entry ?> "." perl-mode-syntax-table)
(modify-syntax-entry ?\\ "\\" perl-mode-syntax-table)
(modify-syntax-entry ?` "\"" perl-mode-syntax-table)
(modify-syntax-entry ?| "." perl-mode-syntax-table)
)
(defvar perl-imenu-generic-expression
'(
;; Functions
(nil "^sub\\s-+\\([-A-Za-z0-9+_:]+\\)\\(\\s-\\|\n\\)*{" 1 )
;;Variables
("Variables" "^\\([$@%][-A-Za-z0-9+_:]+\\)\\s-*=" 1 )
("Packages" "^package\\s-+\\([-A-Za-z0-9+_:]+\\);" 1 )
)
"Imenu generic expression for Perl mode. See `imenu-generic-expression'.")
;; Regexps updated with help from Tom Tromey <tromey@cambric.colorado.edu> and
;; Jim Campbell <jec@murzim.ca.boeing.com>.
(defconst perl-font-lock-keywords-1
'(;; What is this for?
;;("\\(--- .* ---\\|=== .* ===\\)" . font-lock-string-face)
;;
;; Fontify preprocessor statements as we do in `c-font-lock-keywords'.
;; Ilya Zakharevich <ilya@math.ohio-state.edu> thinks this is a bad idea.
("^#[ \t]*include[ \t]+\\(<[^>\"\n]+>\\)" 1 font-lock-string-face)
("^#[ \t]*define[ \t]+\\(\\sw+\\)(" 1 font-lock-function-name-face)
("^#[ \t]*if\\>"
("\\<\\(defined\\)\\>[ \t]*(?\\(\\sw+\\)?" nil nil
(1 font-lock-reference-face) (2 font-lock-variable-name-face nil t)))
("^#[ \t]*\\(\\sw+\\)\\>[ \t]*\\(\\sw+\\)?"
(1 font-lock-reference-face) (2 font-lock-variable-name-face nil t))
;;
;